/*
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
*/
#ifndef I420_RENDER_H
#define I420_RENDER_H

#include "shader_program.h"
#include "egl_render_context.h"
#include <cstdint>
#include <native_window/external_window.h>

class I420Render {
public:
    I420Render() = default;
    ~I420Render();
    int32_t Init(int32_t width, int32_t height, OHNativeWindow *nativeWindow);
    int32_t Render(uint8_t *yData, uint8_t *uData, uint8_t *vData, int32_t frameWidth, int32_t frameHeight);
private:
    int32_t PrepareShader();
    int32_t GenGLResource();
    int32_t width_ {0};
    int32_t height_ {0};
    std::unique_ptr<ShaderProgram> shaderProgram_;
    GLuint vAO_ {0};
    GLuint vBO_ {0};
    GLuint textures_[3] {0};
    EglRenderContext eglRenderContext_;
    OHNativeWindow *nativeWindow_ {nullptr};
    EGLSurface eglSurface_ {EGL_NO_SURFACE};
    static std::string vertexShader_;
    static std::string fragmentShader_;
    static GLfloat vertices_[];
    static GLuint indices_[];
};

#endif // I420_RENDER_H